﻿--[[
    @Copyright 2015, Tencent Inc. All rights reserved.
    @brief    ui logic for network accelerate
    @autor    zhenzhang <zhenzhang@tencent.com>
    @version  1.0
    @date     2015-03-12
]]--

network_acc_control =
{
    is_set_all_game_mode = false;
    --初始化函数
    init = function()
        base_utility.log("network_acc_control.init called");
        ierd_tgp.tpf_ui.Require("tool_box\\model.lua");
        ierd_tgp.tpf_ui.Require("tool_box\\view.lua");
        ierd_tgp.tpf_ui.Require("tool_box\\network_acc\\router_admin_model.lua");
        local tpfui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:AddLuaListener(ierd_tgp.accelerate_module.ACCE_ON_ISP_REFRESH_END, "network_acc_control.acce_on_isp_fresh_end");
        tpfui:AddLuaListener(ierd_tgp.accelerate_module.ACCE_ON_ROUTE_REFRESH, "network_acc_control.acce_on_route_fresh");
        tpfui:AddLuaListener(ierd_tgp.accelerate_module.ACCE_ON_ROUTE_STATUS, "network_acc_control.acce_on_route_status");
        tpfui:AddLuaListener(ierd_tgp.accelerate_module.ACCE_ON_ROUTER_ACCL_SWITCH, "network_acc_control.acce_on_router_accl_switch");
        tpfui:AddLuaListener(ierd_tgp.accelerate_module.ACCE_ON_LSP_REPAIRED, "network_acc_control.acce_on_lsp_repaired");
        tpfui:AddLuaListener(ierd_tgp.accelerate_module.ACCE_ON_ENABLE_HIJACK_NETWORK_END, "network_acc_control.acce_on_enable_hijack_network_end");
        tpfui:AddLuaListener(ierd_tgp.accelerate_module.ACCE_ON_GOT_GAMEZONE_NODE_LIST, "network_acc_control.on_got_gamezone_node_list");

        event_center.add_listener(tool_box_event.TOOL_BOX_ON_JS_CALLBACK_NA, "network_acc_control.on_js_callback");
        event_center.add_listener(tool_box_event.UPDATE_NETWORK_PAGE, "network_acc_control.update_network_page");
        network_acc_control.is_set_all_game_mode = false;
    end;

    update_network_page = function(event_id, json_str)
        -- body
        network_acc_control._set_router_status();
    end;

    get_qbweb = function()
        local uilib = ui_utility.uilib();
        local nQBWebID = uilib:GetControlIDbyCustomID(CID_TOOLBOX_QBWEB);
        local pControl = uilib:GetControlPtr(nQBWebID);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        return pQBWeb;
    end;
    
    -- 请求网络加速的isp信息
    require_network_acc_isp_info = function()
        network_acc_control._set_lsp_status();
    end;

    -- 请求网络加速的router信息
    require_network_acc_router_info = function()
        local device_mgr =
            base_utility.get_component_adapter("IDevice_mgr",
                "ierd_tgp.device.GetDeviceModule();");
        local info = ierd_tgp.device.RouterDeviceStatus:new();
        device_mgr:GetRouterStatus(info);
        if tool_box_model.is_first_open == true then
            tool_box_model.route_info.accl_status = info.accl_status;
            tool_box_model.acc_switch_status = info.accl_status;
            tool_box_model.is_first_open = false;
        else
            tool_box_model.route_info.accl_status = tool_box_model.acc_switch_status;
        end;
        tool_box_model.route_info.accl_status = info.accl_status;
        tool_box_model.route_info.router_model = info.router_model;
        tool_box_model.route_info.vendor = info.vendor;
        ierd_tgp.tpf_ui.Log("[network_acc_contral]router_vendor="..tool_box_model.route_info.vendor);
        network_acc_control._set_router_status();
        info:delete();
    end;
    
    -- 请求网络加速的game列表
    require_network_acc_game_list = function()
        local table  = network_acc_control._get_game_list();
        local json_param = base_utility.table_to_json(table);
        ierd_tgp.tpf_ui.Log("lua_call_JS start.");
        web_utility.lua_call_js('na_set_network_acc_game_list', json_param, CID_TOOLBOX_QBWEB);
        ierd_tgp.tpf_ui.Log("lua_call_JS success.");
    end;
    
    --请求打开运营商选择框
    require_open_isp_window = function()
        event_center.send_event(network_acc_event.OPEN_ISP_WINDOW, "");
    end;
    
    require_open_node_choose_warning = function(json)
        -- 显示warning窗口
        local data_table = {};
        data_table.text = LoadStr(ID_TOOLBOX_SELECT_FAIL);
        data_table.detail = LoadStr(ID_TOOLBOX_SELECT_FAIL_TIP);
        data_table.title = LoadStr(ID_TOOLBOX_WARNING_TITLE);
        data_table.icon = 'warning';

        local new_json = base_utility.table_to_json(data_table);
        event_center.send_event(popup_wnd_event.SHOW_TOOLBOX_WARNING_TIPS, new_json);
    end;

    -- 请求打开加速节点选择框
    require_open_node_choose_window = function(json)
        local table = base_utility.json_to_table(json);
        game_id = table.game_id;
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        local info = ierd_tgp.accelerate_module.GameZoneListInfoPOD:new();
        accModule:get_game_zone_list(game_id, info);
        if info.list_cnt ~= 0 then
            event_center.send_event(network_acc_event.OPEN_NODE_SETTING_WINDOW, json);
        else
            table.text = LoadStr(ID_TOOLBOX_SELECT_FAIL_TIP);
            local new_json = base_utility.table_to_json(table);
            event_center.send_event(network_acc_event.OPEN_NODE_SETTING_WARNING_WINDOW, new_json);
        end
        info:delete();
    end;

    -- 请求转到游戏库
    require_game_library = function(json)
        web_utility.open_link(json);
    end;
    

    require_change_acc_switch = function(json)
        local table = base_utility.json_to_table(json);
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        if accModule == nil then
            return;
        end

        base_utility.log("require_change_acc_switch!, switch to=".. ((table.acc_switch and "on") or "off"));

        -- 打开进度窗口
        local tbl = {
            c_event = ierd_tgp.accelerate_module.ACCE_ON_ENABLE_HIJACK_NETWORK_END,
            title = LoadStr(ID_TOOLBOX_SWITCH_TITLE),
            text = ""
        };
        if table.acc_switch == 1 then
            tbl.text = LoadStr(ID_TOOLBOX_SWITCH_NOW_OPEN);
        else
            tbl.text = LoadStr(ID_TOOLBOX_SWITCH_NOW_CLOSE);
        end
        event_center.send_event(network_acc_event.OPEN_ISP_PROCESS_WINDOW, base_utility.table_to_json(tbl));

        accModule:EnableHijackNetwork(((table.acc_switch == 1 and true) or false));
    end;

    -- 请求设置加速类型
    require_set_acc_mode = function(json)
        local table = base_utility.json_to_table(json);
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        if accModule == nil then
            return;
        end;
        accModule:set_game_acc_mode(table.game_id, table.acc_mode, true,
            ierd_tgp.accelerate_module.ACCE_CHANGE_SOURCE_TOOLBOX);
    end;
    
    -- 请求设置TPLINK游戏mode
    require_set_router_mode = function(json)
        local table = base_utility.json_to_table(json);
        if 'xiaomi' ~= tool_box_model.route_info.vendor and 'huawei' ~= tool_box_model.route_info.vendor and tool_box_model.password_need then
            event_center.send_event(network_acc_event.OPEN_ROUTER_ADMIN_WINDOW, json);
        else
            local router_model = false;
            if table.router_model > 0 then
                router_model = true;
            end
            local password = '';
            local admin_name = '';
            local device_mgr =
                base_utility.get_component_adapter("IDevice_mgr",
                    "ierd_tgp.device.GetDeviceModule();");
            device_mgr:SetRouterAcclEnabled(router_model, admin_name, password);
            -- 调用C++
        end
    end;

    -- 请求修复ISP
    require_repair_isp = function()
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        accModule:fire_lsp_repairing();
    end;


    require_server_list = function(json)
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        local info = ierd_tgp.accelerate_module.GameZoneListInfoPOD:new();
        local src_table = base_utility.json_to_table(json);
        local game_id = src_table.game_id;
        accModule:get_game_zone_list(game_id, info);
        local server_count = info.list_cnt;
        local table = {};
        table.count = server_count;
        table.game_name = game_name;
        table.list = {};
        for i = 0, server_count - 1
            do 
            local item = {};
            item.zone_id = info.list[i].zone_id;
            item.zone_name = info.list[i].zone_name;
            item.type = info.list[i].type;
            table.list[i] = item;
        end
        local json_param = base_utility.table_to_json(table);
        info:delete();
        ierd_tgp.tpf_ui.Log("network_acc_control::send_server_list, lua_call_JS start.");
        web_utility.lua_call_js('na_set_server_list_event', json_param, CID_TOOLBOX_QBWEB);
        ierd_tgp.tpf_ui.Log("network_acc_control::send_server_list, lua_call_JS, success.");
    end;

    require_item_list = function(json)
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        if accModule == nil then
            return;
        end;

        local src_table = base_utility.json_to_table(json);
        local server_id = src_table.server_id;
        local game_id = src_table.game_id;
        accModule:RequestGameZoneAccCfgInfo(game_id, server_id);
    end;

    require_select_node = function(json)
        -- 发送到c++
        local param = base_utility.json_to_table(json);
        local game_id = param.game_id;

        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        if accModule == nil then
            return;
        end;
        local remember_node = accModule:GetNeedRememberAccNode(game_id);

        accModule:set_game_zone_acc_cfg(param.game_id, param.server_id, param.item_id,
            ierd_tgp.accelerate_module.ACCE_CHANGE_SOURCE_TOOLBOX);
 
        -- 显示warning窗口
        local data_table = {};
        data_table.text = LoadStr(ID_TOOLBOX_SET_OK);
        if remember_node then
            data_table.detail = LoadStr(ID_TOOLBOX_NEXT_DEFAULT_TIP) ..'"'.. param.node_name .. '"';
        else
            data_table.detail = LoadStr(ID_TOOLBOX_NEXT_RESTORE);
        end
        data_table.icon = 'success';
        data_table.title = LoadStr(ID_TOOLBOX_WARNING_TITLE);

        local new_json = base_utility.table_to_json(data_table);
        event_center.send_event(popup_wnd_event.SHOW_TOOLBOX_WARNING_TIPS, new_json);
    end;

    require_get_remember_node = function(json)
        -- 发送到c++
        local param = base_utility.json_to_table(json);
        local game_id = param.game_id;

        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        if accModule == nil then
            return;
        end;

        local remember_node = accModule:GetNeedRememberAccNode(game_id);
 
        -- 发送到js
        local json_param = base_utility.table_to_json({remember = remember_node});
        ierd_tgp.tpf_ui.Log("network_acc_control::require_get_remember_node, lua_call_JS start.");
        web_utility.lua_call_js('na_set_remember_node', json_param, CID_TOOLBOX_QBWEB);
        ierd_tgp.tpf_ui.Log("network_acc_control::require_get_remember_node, lua_call_JS, success.");
    end;


    require_set_remember_node = function(json)
        -- 发送到c++
        local param = base_utility.json_to_table(json);
        local game_id = param.game_id;
        local need_remeber = param.need_remember;

        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        if accModule == nil then
            return;
        end;

        local remember_node = accModule:SetNeedRememberAccNode(game_id, need_remeber);
    end;

    require_set_isp_info = function(json)
        -- 设置isp
        local param = base_utility.json_to_table(json);

        local isp_id = param.isp_id;
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        if accModule == nil then
            return;
        end

        -- 打开进度窗口
        local tbl = {
            c_event = ierd_tgp.accelerate_module.ACCE_ON_ISP_REFRESH_END,
            title = LoadStr(ID_TOOLBOX_NET_NODE_UPDATE),
            text = LoadStr(ID_TOOLBOX_SPEED_TEST_UPDATE)
        };
        event_center.send_event(network_acc_event.OPEN_ISP_PROCESS_WINDOW, base_utility.table_to_json(tbl));

        accModule:set_selected_isp(isp_id);
    end;
    
    -- lsp变化之后
    acce_on_isp_fresh_end = function()
        network_acc_control._set_lsp_status();
    end;

    -- router刷新之后
    acce_on_route_fresh = function()
        network_acc_control._update_game_list();
    end;

    -- router状态变化之后（c++主动探测）
    acce_on_route_status = function(event_id, jsonp)
        local data_table = base_utility.json_to_table(jsonp);
        tool_box_model.route_info.accl_status = data_table.accl_status;
        tool_box_model.route_info.router_model = data_table.router_model;
        tool_box_model.route_info.vendor = data_table.vendor;

        if router_admin_model.router_admin_shown then
            base_utility.log("Because of admin shown, set router does not refresh!");
        else
            network_acc_control._set_router_status();
        end;
    end;

    -- 切换router开关之后
    acce_on_router_accl_switch = function(event_id, jsonp)
        local data_table = base_utility.json_to_table(jsonp);
        tool_box_model.route_info.accl_status = data_table.status;

        network_acc_control._set_router_status();

        -- 弹出结果框，复用加速节点选择的提示框
        if data_table.result ~= 0 then
            data_table.text = LoadStr("TOOL_BOX_NETWORK_ACC_CONTROL_FAIL");
            tool_box_model.password_need = true;
        else
            data_table.text = LoadStr("TOOL_BOX_NETWORK_ACC_CONTROL_SUCCESS");
            tool_box_model.password_need = false;
            -- 此处记录下本地开关状态
            tool_box_model.acc_switch_status = data_table.status;
        end
        local new_json = base_utility.table_to_json(data_table);
        event_center.send_event(network_acc_event.OPEN_NODE_SETTING_WARNING_WINDOW, new_json);
    end;

    -- 修复lsp之后
    acce_on_lsp_repaired = function(event_id, jsonp)
        network_acc_control._set_lsp_status();
        network_acc_control._update_game_list();

        local data_table = base_utility.json_to_table(jsonp);
        if data_table.status == 2 then
            data_table.text = LoadStr(ID_TOOLBOX_ISP_FIX_FAIL);
            data_table.icon = 'error';
        else
            data_table.text = LoadStr(ID_TOOLBOX_ISP_FIX_OK);
            data_table.icon = 'success';
        end
        local new_json = base_utility.table_to_json(data_table);
        event_center.send_event(popup_wnd_event.SHOW_TOOLBOX_WARNING_TIPS, new_json);
    end;

    acce_on_enable_hijack_network_end = function(event_id, jsonp)
        base_utility.log("acce_on_enable_hijack_network_end called!");

        -- 发送到js
        ierd_tgp.tpf_ui.Log("network_acc_control::acce_on_enable_hijack_network_end, lua_call_JS start.");
        web_utility.lua_call_js('na_set_hijack_switch', jsonp, CID_TOOLBOX_QBWEB);
        ierd_tgp.tpf_ui.Log("network_acc_control::acce_on_enable_hijack_network_end, lua_call_JS, success.");
    end;

    on_got_gamezone_node_list = function(event_id, jsonp)
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        local src_table = base_utility.json_to_table(jsonp);
        local server_id = src_table.server_id;
        local game_id = src_table.game_id;
        local is_auto_temp = false;
        local auto_selected_node = ierd_tgp.accelerate_module.AcceNodeInfoPOD:new();
        local node_list = ierd_tgp.accelerate_module.AcceNodeListInfoPOD:new();
        is_auto_temp = accModule:get_game_zone_acc_cfg_info(game_id, server_id, is_auto_temp,
            auto_selected_node, node_list);
        local node_count = node_list.list_cnt;
        local table = {};

        --节点个数 
        table.count = node_count;

        --节点列表
        table.list = {};
        for i = 0, node_count -1
            do 
            local item = {};
            item.game_idc_id = node_list.list[i].game_idc_id;
            item.acc_idc_id = node_list.list[i].acc_idc_id;
            item.idc_name = node_list.list[i].idc_name;
            item.section1_delay = node_list.list[i].section1_delay;
            item.section2_delay = node_list.list[i].section2_delay;
            item.delay_total = node_list.list[i].delay_total;
            item.lost = node_list.list[i].lost;
            table.list[i+1] = item;
        end

        -- 是否自动
        local auto_select_node_temp = auto_selected_node;
        table.is_auto = is_auto_temp;
        -- 自动选择的节点
        table.auto_selected_node = {};
        if auto_select_node_temp ~= nil then
            table.auto_selected_node.game_idc_id = auto_select_node_temp.game_idc_id;
            table.auto_selected_node.acc_idc_id = auto_select_node_temp.acc_idc_id;
            table.auto_selected_node.idc_name = auto_select_node_temp.idc_name;
            table.auto_selected_node.section1_delay = auto_select_node_temp.section1_delay;
            table.auto_selected_node.section2_delay = auto_select_node_temp.section2_delay;
            table.auto_selected_node.delay_total = auto_select_node_temp.delay_total;
            table.auto_selected_node.lost = auto_select_node_temp.lost;
        end

        table.real_ping = -1;
        if accModule ~= nil then
            table.real_ping = accModule:get_real_ping(game_id, server_id);
        end

        -- 发送到js
        local json_param = base_utility.table_to_json(table);
        ierd_tgp.tpf_ui.Log("network_acc_control::send_item_list, lua_call_JS start.");
        web_utility.lua_call_js('na_set_item_list_event', json_param, CID_TOOLBOX_QBWEB);
        ierd_tgp.tpf_ui.Log("network_acc_control::send_item_list, lua_call_JS, success.");
        auto_selected_node:delete();
        node_list:delete();
    end;

    --接收消息from JS
    on_js_callback = function(event_id, jsonp)
        local data_table = base_utility.json_to_table(jsonp);
        local fuc_name = data_table["fuc_name"];
        local json = data_table["json"];
        local table = base_utility.json_to_table(json);
        local op_name = table.op;
        if op_name == "require_network_acc_isp_info" then
            network_acc_control.require_network_acc_isp_info();
        elseif op_name == "require_network_acc_router_info" then
            network_acc_control.require_network_acc_router_info();
        elseif op_name == "require_network_acc_game_list" then
            network_acc_control.require_network_acc_game_list();
        elseif op_name == "require_open_isp_window" then
            network_acc_control.require_open_isp_window();
        elseif op_name == "require_open_node_choose_warning" then
            network_acc_control.require_open_node_choose_warning(json);
        elseif op_name == "require_game_library" then
            network_acc_control.require_game_library(json);
        elseif op_name == "require_set_acc_mode" then
            network_acc_control.require_set_acc_mode(json);
        elseif op_name == "require_set_router_mode" then
            network_acc_control.require_set_router_mode(json);
        elseif op_name == "require_repair_isp" then
            network_acc_control.require_repair_isp();
        elseif op_name == "open_game_library" then
            network_acc_control.open_game_library(json);
        elseif op_name == "require_server_list" then
            network_acc_control.require_server_list(json);
        elseif op_name == "require_item_list" then
            network_acc_control.require_item_list(json);
        elseif op_name == "require_select_node" then
            network_acc_control.require_select_node(json);
        elseif op_name == "require_get_remember_node" then
            network_acc_control.require_get_remember_node(json);
        elseif op_name == "require_set_remember_node" then
            network_acc_control.require_set_remember_node(json);
        elseif op_name == "require_set_isp_info" then
            network_acc_control.require_set_isp_info(json);
        elseif op_name == "require_change_acc_switch" then
            network_acc_control.require_change_acc_switch(json);
        end;
    end;

    _is_showed_in_banner_list = function(game_id)
        return banner_model.is_showed_in_banner_list(game_id);
    end;

    -- 刷新游戏列表
    _update_game_list = function()
        local table  = network_acc_control._get_game_list();
        local json_param = base_utility.table_to_json(table);
        ierd_tgp.tpf_ui.Log("[]lua_call_JS start.");
        web_utility.lua_call_js('na_update_network_acc_game_list', json_param, CID_TOOLBOX_QBWEB);
        ierd_tgp.tpf_ui.Log("lua_call_JS success.");
    end;

    -- 获取游戏列表
    _get_game_list = function()
		if network_acc_control.is_set_all_game_mode == true then
			return;
		end
		
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        local isp_status = accModule:get_lsp_status();
        -- isp_status = 2;
        local game_acc_cfg_list = ierd_tgp.accelerate_module.GameAccCfgListInfoPOD:new();
        accModule:get_game_acc_cfg_list(game_acc_cfg_list);
        local gameCount = game_acc_cfg_list.list_cnt;

        local table = {};
        table.isp_status = isp_status;
        table.hijack_switch = (accModule:IsHijackNetworkEnable() and 1) or 0;
        table.count = 0;
        table.list = {};
        local filter_count = 0;

        -- 本地安装并且在可见游戏列表中，才在工具箱中显示
        local installed_game_list = ierd_tgp.game_library.Game_list:new_local();
        local gl_adapter =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
        if gl_adapter ~= nil then
            gl_adapter:get_installed_games(installed_game_list);
        end
        base_utility.log('installed_game_list,count:'..tostring(installed_game_list.count));
        
        for i = 0, gameCount - 1
            do 
            local game = game_acc_cfg_list.list[i];
            local gameID = game.game_id;

            local installed = false;
            if installed_game_list ~= nil and 
               installed_game_list.count ~= nil and 
               installed_game_list.game_id_list ~= nil then
                for j = 0, installed_game_list.count - 1  do
                    if installed_game_list.game_id_list[j] ~= nil and 
                       installed_game_list.game_id_list[j] == gameID then
                        installed = true;
                        break;
                    end
                end
             end
            local is_showed_in_list = network_acc_control._is_showed_in_banner_list(gameID);

            base_utility.log('[_get_game_list] id:'..tostring(gameID) ..',installed:'
                             ..tostring(installed)..',visible:'..tostring(is_showed_in_list));

            if installed == true and is_showed_in_list == true then
                local selectedServerID = 0;
                local has_zone_list = false;

                local gameZoneList = ierd_tgp.accelerate_module.GameZoneListInfoPOD:new();
                accModule:get_game_zone_list(gameID, gameZoneList);
                if gameZoneList.list_cnt > 0 then
                    has_zone_list = true;
                else
                    has_zone_list = false;
                end

                local lastSelectedID = game_lib:get_last_selected_server(gameID);
                if lastSelectedID > 0 then
                    selectedServerID = lastSelectedID;
                else
                    if gameZoneList.list_cnt > 0 then
                        selectedServerID = gameZoneList.list[0].zone_id;
                    end
                end

                gameZoneList:delete();

                local server_info = ierd_tgp.game_library.GameServerInfo:new(); 
                game_lib:get_server_acc_info(server_info, gameID, selectedServerID);

                local acceModule =
                    base_utility.get_component_adapter("IAccelerate_module",
                        "ierd_tgp.accelerate_module.GetAcceModule();");
                local info = ierd_tgp.accelerate_module.AcceCenterBaseInfoPOD:new();
                acceModule:get_acc_center_basic_info(info);
                local is_multi_isps = (info.dwExport_ip_cnt > 0);

                local item = {};
                item.game_id = gameID;
                item.game_name = game.game_name;
                item.e_name = game.e_name;
                item.zone_name = server_info.name;
                item.proxy_name = server_info.acce_info.proxy_name;
                item.img_url = game.game_icon_url;
                item.acc_mode = game.acc_mode;
                item.node_select_enable = game.node_select_enable;
                item.is_multi_isps = is_multi_isps;
                item.decision = server_info.acce_info.decision_code;
                item.direct_delay_raw = server_info.acce_info.direct_delay_raw;
                item.proxy_delay_raw_t1 = server_info.acce_info.proxy_delay_raw_t1;
                item.proxy_delay_raw_t2 = server_info.acce_info.proxy_delay_raw_t2;
                item.has_zone_list = has_zone_list;

                item.real_ping = -1;
                if acceModule ~= nil then
                    item.real_ping = acceModule:get_real_ping(gameID, selectedServerID);
                end;
                table.list[filter_count] = item;
                filter_count = filter_count + 1;
                server_info:delete();
            end            
        end
        game_acc_cfg_list:delete();
        table.count = filter_count;
        return table;
    end;

    --设置路由状态
    _set_router_status = function()
        local table = tool_box_model.route_info;
        local json_param = base_utility.table_to_json(table);
        ierd_tgp.tpf_ui.Log("lua_call_JS start.");
        web_utility.lua_call_js('na_set_network_acc_router_info' ,json_param, CID_TOOLBOX_QBWEB);
        ierd_tgp.tpf_ui.Log("lua_call_JS success.");
    end;

    --设置lsp状态
    _set_lsp_status = function()
        local accModule =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        local info = ierd_tgp.accelerate_module.AcceCenterBaseInfoPOD:new();
        accModule:get_acc_center_basic_info(info);
        local table = {};
        table.selected_isp_id = info.dwSelected_isp_id;
        table.checked_isp_id = info.dwChecked_isp_id;
        table.export_ip_cnt = info.dwExport_ip_cnt;
        table.export_ip_list = {};
        for i = 0, table.export_ip_cnt - 1
            do
            local item = {};
            item.dw_isp = info.astExport_ip_list[i].dwIsp;
            item.sz_ip = info.astExport_ip_list[i].szIp;
            table.export_ip_list[i] = item;
        end
        local json_param = base_utility.table_to_json(table);
        ierd_tgp.tpf_ui.Log("show user lsp:" .. table.checked_isp_id);
        ierd_tgp.tpf_ui.Log("lua_call_JS start.");
        web_utility.lua_call_js('na_set_network_acc_isp_info' ,json_param, CID_TOOLBOX_QBWEB);
        ierd_tgp.tpf_ui.Log("lua_call_JS success.");
        info:delete();
    end;

    open_game_library = function(json)
        web_utility.open_link(base_utility.table_to_json(json));
    end;

};

network_acc_control.init();